<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%# encoding:utf-8 %>
<html>
<head>
  <title>HappyERP Touch</title>
  <%= stylesheet_link_tag "/javascripts/touch23/resources/css/sencha-touch.css" %>
  <%= javascript_include_tag "touch23/sencha-touch-all-debug.js" %>
</head>
<body>
<script type="text/javascript">

    Ext.setup({
        icon: 'icon.png',
        tabletStartupScreen: 'tablet_startup.png',
        phoneStartupScreen: 'phone_startup.png',
        glossOnIcon: false,
        onReady: function () {
            var loginForm = Ext.create('Ext.form.Panel', {
                //fullscreen: true,
                modal: true,
                method: 'GET',
                width: 400,
                height:160,
                url: '/index/validate_user',
                items: [
                    {
                        xtype: 'fieldset',
                        items: [
                            {
                                xtype: 'textfield',
                                name: 'user_name',
                                label: 'Name'
                            },
                            {
                                xtype: 'passwordfield',
                                name: 'pwd',
                                label: 'Password'
                            },
                            {
                                xtype: 'hiddenfield',
                                name: 'company_id',
                                value:'1'
                            },
                            {
                                layout:{
                                    pack: 'center'
                                },
                                xtype: 'toolbar',
                                pack: 'center',
                                items: [
                                    {
                                        xtype: 'button',
                                        text: 'Submit Data',
                                        handler: function () {
                                            Ext.Ajax.request({
                                                url: "/index/validate_user",
                                                params: loginForm.getValues(),
                                                success: function(response){
                                                    var text = response.responseText;
                                                    console.info(text)
                                                    if(Ext.JSON.decode(text).info == "成功"){
                                                        window.document.location.href = '/'
                                                    }else{
                                                        console.info("失败");
                                                    }
                                                    //window.document.location.href = '/';
                                                    // process server response here
                                                }
                                            });
                                        }
                                    }
                                ]
                            }
                        ]
                    }
                ]
            });


            Ext.create('Ext.Container', {
                fullscreen: true,
                layout:{
                    type:'hbox',
                    align:'middle',
                    pack : 'center'
                },
                items: [
                    loginForm
                ]
            });

            loginForm.show();
        }
    })

</script>
</body>